package com.example.search.controller;

import com.example.common.Dto;
import com.example.common.DtoUtil;
import com.example.search.service.DoctorSearchService;
import com.example.vo.SearchDoctorReturnVo;
import com.example.vo.SearchDoctorVO;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

import static com.example.utils.ErrorCode.SEARCH_abnormal_FAILED;

/**
 * Created by LENOVO on 2018/9/25.
 */
@Controller
@RequestMapping("/api")
public class DoctorSearchController {

    @Resource
    private DoctorSearchService doctorSearchService;


    @ApiOperation(value="查询医生列表信息",httpMethod = "POST", protocols = "HTTP", produces = "application/json", response = Dto.class,notes="查询医生列表信息")
    @RequestMapping(value = "/dotorList/searchDotorList", produces = "application/json", method = RequestMethod.POST)
    @ResponseBody
    public Dto searchDotorList(@ApiParam(name="searchDoctorVO",value="搜索条件",required=true)SearchDoctorVO searchDoctorVO)
    {
        SearchDoctorReturnVo searchDoctorReturnVo =null;
        try {
            searchDoctorReturnVo =doctorSearchService.searchDoctorList(searchDoctorVO);
        }
        catch (Exception e) {
            e.printStackTrace();
            return DtoUtil.returnFail("获取医生列表信息失败！", SEARCH_abnormal_FAILED);
        }
        if(searchDoctorReturnVo !=null)
        {
            return DtoUtil.returnSuccess("查询医生列表成功!", searchDoctorReturnVo);
        }
        else
        {
            return DtoUtil.returnSuccess("没有医生数据，请重新查询", searchDoctorReturnVo);
        }
    }
}
